<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


	<xsl:include href="main.xsl"/>

	<!--
	additional scripts
	-->
	<xsl:template mode="script" match="/">
		<script type="text/javascript" language="JavaScript">
			function update1()
			{
				if (document.branchUpdateForm.name.value.length &lt; 1)
				{
					alert('A branch name must be filled in.');
					return;
				}
				sendForm( document.branchUpdateForm );
			}
			function confirmDelete(url)
			{
				if(confirm("Delete the selected element ?"))
					sendUrl(url);
			}
		</script>
	</xsl:template>
	
	<!--
	page content
	-->
	<xsl:template name="content">
		<xsl:call-template name="formLayout">
			<xsl:with-param name="title">
				<xsl:choose>
					<xsl:when test="/root/response/record/id">
						<xsl:value-of select="/root/gui/strings/updateBranch"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="/root/gui/strings/newBranch"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="menu">admin</xsl:with-param>
			<xsl:with-param name="content">
				<xsl:call-template name="form"/>
			</xsl:with-param>
			<xsl:with-param name="buttons">
                            <!--
				<button class="content" onclick="goBack()"><xsl:value-of select="/root/gui/strings/back"/></button>
                                -->
				&#160;
				<button class="content" onclick="update1()"><xsl:value-of select="/root/gui/strings/save"/></button>
				<xsl:call-template name="branch-detail-list"/>
				<xsl:call-template name="branch-area-list"/>		
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	
	<!--
	form
	-->
	<xsl:template name="form">
		<div class="important"><xsl:value-of select="/root/gui/strings/localizationHelp"/></div>
		<form name="branchUpdateForm" accept-charset="UTF-8" action="{/root/gui/locService}/branch.update" method="post">
			<input type="submit" style="display: none;" />
			<input type="hidden" name="commit" id="commit" value="true"  />
			<xsl:if test="/root/response/record/id">
				<input type="hidden" id="id" name="id" value="{/root/response/record/id}"/>
			</xsl:if>
			<xsl:if test="/root/response/record/id_organization">
				<input type="hidden" name="parentId" id="parentId" value="{/root/response/record/id_organization}"/>
			</xsl:if>
			<xsl:if test="/root/id_organization">
				<input type="hidden" name="parentId"  id="parentId" value="{/root/id_organization}"/>
			</xsl:if>
			<table width="70%">
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/name"/></th>
					<td class="padded"><input class="content" type="text" name="name" value="{/root/response/record/name}" size="60"/></td>
				</tr>
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/service_hours"/></th>
					<td class="padded"><input class="content" type="text" name="service_hours" value="{/root/response/record/service_hours}" size="60"/></td>
				</tr>
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/country"/></th>
					<td class="padded">
						<select class="content" size="1" name="country">
							<xsl:if test="string(/root/response/record/country)=''">
								<option value=""/>
							</xsl:if>
							<xsl:for-each select="/root/gui/countries/country">
								<option value="{@iso2}">
									<xsl:if test="string(/root/response/record/country)=@iso2">
										<xsl:attribute name="selected"/>
									</xsl:if>
									<xsl:value-of select="."/>
								</option>
							</xsl:for-each>
						</select>
					</td>
				</tr>
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/contact_instructions"/></th>
					<td class="padded"><textarea  cols="60" rows="4" class="content" name="contact_instructions"><xsl:value-of select="/root/response/record/contact_instructions"/></textarea></td>
				</tr>
			</table>
		</form>
	</xsl:template>
	<xsl:template name="branch-detail-list">
			<table width="70%" border="0" cellpadding="4">
			<tr>
				<td height="30">
				</td>
			</tr>
			<tr>
				<td height="30">
				<b><xsl:value-of select="/root/gui/strings/detailInfo"/></b>
				</td>
			</tr>
			<tr>
					<td align="center">
					
			<form name="branchUpdateFormAddDetail" accept-charset="UTF-8" action="{/root/gui/locService}/branch.update" method="post">
			<input type="submit" style="display: none;" />
			<input type="hidden" id="new_detail" name="new_detail" value="true" />
			<xsl:if test="/root/response/record/id">
				<input type="hidden" id="id" name="id" value="{/root/response/record/id}"/>
			</xsl:if>
			<xsl:if test="/root/response/record/id_organization">
				<input type="hidden" id="parentId" name="parentId" value="{/root/response/record/id_organization}"/>
			</xsl:if>
			<xsl:if test="/root/id_organization">
				<input type="hidden" id="parentId"  name="parentId" value="{/root/id_organization}"/>
			</xsl:if>
			<table width="100%" border="0" cellpadding="4">
			
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/branchDetailValue"/></th>
					<td class="padded"><input class="content" type="text" name="detail_value" size="60"/></td>
				</tr>
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/branchDetailType"/></th>
					<td class="padded"><select name="detail_type">
											<xsl:for-each select="/root/gui/strings/branchDetailChoice">
												<option value="{@value}">
													<xsl:value-of select="."/>
												</option>
											</xsl:for-each>
										</select>
					</td>
				</tr>
				<tr><td colspan="2"><button class="content" onclick="sendForm( document.branchUpdateFormAddDetail );"><xsl:value-of select="/root/gui/strings/newElement"/></button>
				</td></tr>
				</table>
			</form>
			</td>
			</tr>
			<tr>
				<td height="20">
				</td>
			</tr>
			<xsl:if test="/root/response/record/id">
			<tr>
				<td align="center">				
					<table width="70%" border="0" cellpadding="4">
						<tr>
							<th class="padded, bottom_border"><xsl:value-of select="/root/gui/strings/branchDetailValue"/></th>
							<th class="padded, bottom_border"><xsl:value-of select="/root/gui/strings/branchDetailType"/></th>
							<th class="padded"><xsl:value-of select="/root/gui/strings/operation"/></th>
						</tr>
						<xsl:for-each select="/root/response/branch_detail/response/record">
							<tr>
								<td class="padded, bottom_border"><xsl:value-of select="detail_value"/></td>
								<td class="padded, bottom_border"><xsl:value-of select="detail_type"/></td>
								<td class="padded" width="150px">
									<button class="content" onclick="confirmDelete('{/root/gui/locService}/branch_detail.remove?id={id}&amp;parentId=' + document.getElementById('parentId').value )"><xsl:value-of select="/root/gui/strings/delete"/></button>
								</td>
							</tr>
						</xsl:for-each>
					</table>
				</td>
			</tr>		
			</xsl:if>
			</table>		
		</xsl:template>
		<xsl:template name="branch-area-list">
			<table width="70%" border="0" cellpadding="4">
			<tr>
				<td height="30">
				</td>
			</tr>
			<tr>
				<td height="30">
				<b><xsl:value-of select="/root/gui/strings/areas"/></b>
				</td>
			</tr>
			<tr>
					<td align="center">
					
			<form name="branchUpdateFormAddArea" accept-charset="UTF-8" action="{/root/gui/locService}/branch.update" method="post">
			<input type="submit" style="display: none;" />
			<input type="hidden" name="commit" id="commit" value="true"  />
			<input type="hidden" id="new_area" name="new_area" value="true" />
			<xsl:if test="/root/response/record/id">
				<input type="hidden" name="id" value="{/root/response/record/id}"/>
			</xsl:if>
			<xsl:if test="/root/response/record/id_organization">
				<input type="hidden" name="parentId" value="{/root/response/record/id_organization}"/>
			</xsl:if>
			<xsl:if test="/root/id_organization">
				<input type="hidden" name="parentId" value="{/root/id_organization}"/>
			</xsl:if>
			<table width="100%" border="0" cellpadding="4">
			
				<tr>
					<th class="padded"><xsl:value-of select="/root/gui/strings/area"/></th>
					<td class="padded"><input class="content" type="text" name="name" size="60"/></td>
				</tr>
				<tr><td colspan="2"><button class="content" onclick="sendForm( document.branchUpdateFormAddArea );"><xsl:value-of select="/root/gui/strings/newElement"/></button>
				</td></tr>
				</table>
			</form>
			</td>
			</tr>
			<tr>
				<td height="20">
				</td>
			</tr>
			<xsl:if test="/root/response/record/id">
			<tr>
				<td align="center">				
					<table width="70%" border="0" cellpadding="4">
						<tr>
							<th class="padded, bottom_border"><xsl:value-of select="/root/gui/strings/name"/></th>
							<th class="padded"><xsl:value-of select="/root/gui/strings/operation"/></th>
						</tr>
						<xsl:for-each select="/root/response/area/response/record">
							<tr>
								<td class="padded, bottom_border"><xsl:value-of select="name"/></td>
								<td class="padded" width="150px">
									<button class="content" onclick="confirmDelete('{/root/gui/locService}/branch_area.remove?id={id}&amp;parentId=' + document.getElementById('parentId').value )"><xsl:value-of select="/root/gui/strings/delete"/></button>
								</td>
							</tr>
						</xsl:for-each>
					</table>
				</td>
			</tr>		
			</xsl:if>
			</table>		
		</xsl:template>
</xsl:stylesheet>
